/**
 * Created by Dalyn on 2017/4/13.
 */
import React from "react";
import "./css/OrderDetailPartB.css"
import "./css/OrderDetail.css"
import AcceptOrderMutation from "../mutation/AcceptOrderMutation"
import Relay from "react-relay";
import Reactkey from "../../../util/ReactKey"

export default class OrderdetailPartB extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            partAName:'',
            address:'',
            linkman:'',
            isaccept:false
        };
        this.enid = sessionStorage.getItem('enterpriseId');
        this.order = "";

    }
    componentWillMount(){
        // console.log(this.props.order);
        this.order = this.props.order? this.props.order : "";
        // console.log(this.order.orderType);
        // console.log(this.order);
        let orderOperates = this.order.orderOperates?this.order.orderOperates:[];
        // console.log(orderOperates);
        if(this.order.status=="2"){
            orderOperates.map((item,index)=>{
                if(item.status=="2"&& item.toId == this.enid){
                    this.setState({
                        isaccept:true,
                    });
                }
            });
        }
        if(this.order.status>="3"){
            this.setState({
                isaccept:true,
            });
        }
    }
    resaveorder(e){
        Relay.Store.commitUpdate(
            new AcceptOrderMutation({
                orderId:this.props.oid,
                enId:this.enid,
            }),
            {
                onFailure: () => {

                },
                onSuccess: (response) => {
                    let errorCode = response.acceptOrder.acceptOrder.errorCode;
                    if(errorCode == 0){
                        this.setState({
                            isaccept:true,
                        },()=>{
                          this.props.Orderdetail()
                        });
                    }
                }
            }
        )
    }
    addpartbInfo(){
        /*已签订--3*/
        // console.log(this.order.orderType);
        // console.log(this.order.partB);
        if(this.order.status&&this.order.status>="3"){
            /*已签订-是自己-显示乙方*/
            if(this.order.partB&&this.enid == this.order.partB){
                return(
                    <div className="order_detail_customer_inforight">
                        <p className="order_detail_customer_infop">
                            <span className="order_detail_customer_infospan1">乙方：</span>
                            <span className="order_detail_customer_infospan2">{this.order.partBName == null || this.order.partBName == 'null' ? '' : this.order.partBName}</span>
                        </p>
                        <p className="order_detail_customer_infop">
                            <span className="order_detail_customer_infospan1">地址：</span>
                            <span className="order_detail_customer_infospan2">{this.order.partBAddress == null || this.order.partBAddress == 'null' ? '' : this.order.partBAddress}</span>
                        </p>
                        <p className="order_detail_customer_infop">
                            <span className="order_detail_customer_infospan1">联系人：</span>
                            <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.order.partBUserName == null || this.order.partBUserName == 'null' ? '' : this.order.partBUserName}</span>
                            <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.order.partBPhone == null || this.order.partBPhone == 'null' ? '' : this.order.partBPhone}</span>
                        </p>
                    </div>
                )
            }else if(this.order.partB&&this.enid != this.order.partB){
                /*已签订-不是自己-已失效*/
                return(
                    <div className="order_detail_customer_inforight clear">
                       <div className="order_detail_customer_lapsed"></div>
                    </div>
                )
            }
        }else{
            /*不显示乙方*/
            return(
                <div>

                </div>
            )
        }
    }

    render() {
        return (
            <div>
                {/*订单编号*/}
                <div className="order_detail_orderId">
                    <p className="order_detail_addpart_orderp" style={{borderBottom:'1px solid #ededed'}}>订单编号：{this.order.oid}</p>
                    {
                      // <div className={this.state.isaccept?"order_detail_partb_ordernumborder_saveordertrue":"order_detail_partb_ordernumborder_saveorder"} onClick={this.resaveorder.bind(this)}>接单</div>
                      // <div className={this.state.isaccept&&this.order.status=="2" ? "order_detail_partb_ordernumborder_saveorder":"order_detail_partb_ordernumborder_saveordertrue "} style={{background: 'none',color:'#36b3b3',width:'240px'}}>您已成功接单，请等待甲方签订合同。</div>
                    }
                  <div className="order_detail_customer_info clear">
                        <div className="order_detail_customer_infoleft">
                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">甲方：</span>
                                <span className="order_detail_customer_infospan2">{this.order.partAName == null || this.order.partAName == 'null' ? '' : this.order.partAName}</span>
                            </p>

                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">地址：</span>
                                <span className="order_detail_customer_infospan2">{this.order.partAAddress == null || this.order.partAAddress == 'null' ? '' : this.order.partAAddress}</span>
                            </p>

                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">联系人：</span>
                                <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.order.partAUserName == null || this.order.partAUserName == 'null' ? '' : this.order.partAUserName}</span>
                                <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.order.partAPhone == null || this.order.partAPhone == 'null' ? '' : this.order.partAPhone}</span>
                            </p>
                        </div>
                            {
                                this.addpartbInfo()
                            }

                    </div>
                </div>

            </div>
        );
    }
}
